package com.tuzhi.test;

import javax.crypto.Cipher;
import java.security.PublicKey;

public class RSAEncryptor {

    private final PublicKey publicKey;

    public RSAEncryptor(PublicKey publicKey) {
        this.publicKey = publicKey;
    }

    public byte[] encrypt(String data) throws Exception {
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        return cipher.doFinal(data.getBytes());
    }

}
